/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package edu.mobbuzz.renderer;

import com.sun.lwuit.Component;
import com.sun.lwuit.Container;
import com.sun.lwuit.Font;
import com.sun.lwuit.Image;
import com.sun.lwuit.Label;
import com.sun.lwuit.List;
import com.sun.lwuit.layouts.BorderLayout;
import com.sun.lwuit.layouts.BoxLayout;
import com.sun.lwuit.list.ListCellRenderer;
import com.sun.lwuit.util.Resources;
import edu.mobbuzz.bean.Message;
import java.io.IOException;

/**
 *
 * @author penyihir kecil
 */
public class MessageRenderer extends Container implements ListCellRenderer {

        private Label titleLbl = new Label("");
        private Label descLbl = new Label("");
        private Label pic = new Label("");
        private Image icon = null;
        private Label focus = new Label("");
        
        private Resources resources;
        private Font fontDescriptionStyle;
        
        public MessageRenderer() {
            setLayout(new BorderLayout());
            addComponent(BorderLayout.WEST, pic);
            Container cnt = new Container(new BoxLayout(BoxLayout.Y_AXIS));
            titleLbl.getStyle().setBgTransparency(0);  
            titleLbl.getStyle().setFont(Font.createSystemFont(Font.FACE_PROPORTIONAL, Font.STYLE_BOLD, Font.SIZE_SMALL));
            titleLbl.getStyle().setFont(getFontDescriptionStyle("SansSerif"));
            descLbl.getStyle().setBgTransparency(0);
            descLbl.getStyle().setFont(getFontDescriptionStyle("SansSerif"));
            pic.getStyle().setBgTransparency(0);
            
            cnt.addComponent(titleLbl);
            cnt.addComponent(descLbl);
            
            addComponent(BorderLayout.CENTER, cnt);
            focus.getStyle().setBgTransparency(100);
            focus.getStyle().setBgColor(0xCCCCCC);
        }

        public Component getListCellRendererComponent(List list, Object value, int index, boolean isSelected) {
            try {
                icon = Image.createImage("/icons/read.png");
            } catch (IOException ex) {
                ex.printStackTrace();
            }

            Message contact = (Message) value;
            titleLbl.setText(contact.getTitle());
            descLbl.setText(contact.getDesc());
            pic.setIcon(icon);
            return this;
        
        }

        public Component getListFocusComponent(List list) {
            return focus;
        }
        
        public Resources getResources() {
            try {
                resources = Resources.open("/mobbuzz.res");
            } catch (IOException ex) {
                ex.printStackTrace();
            }
            return resources;
        }

        public Font getFontDescriptionStyle(String fontType) {
            fontDescriptionStyle = getResources().getFont(fontType);
            return fontDescriptionStyle;
        }

    
    }
